/**
 * Created with IntelliJ IDEA.
 * Description: 牛客网.把字符串转换成整数
 */
class Solution {
    public static int StrToInt(String str) {
        int ans = 0;
        int flag = 0;
        if(str.length() == 0 || str.charAt(0) != '+' && str.charAt(0) != '-' && (str.charAt(0) < '0' || str.charAt(0) > '9')) {
            return 0;
        }
        if(str.charAt(0) == '+' || str.charAt(0) == '-') {
            flag = 1;
        }
        for(int i = flag; i < str.length(); i++) {
            if(str.charAt(i) >= '0' && str.charAt(i) <= '9') {
                ans *= 10;
                ans += (str.charAt(i) - '0');
            } else {
                return 0;
            }
        }
        if(flag == 1) {
            ans *= (44 - str.charAt(0));
        }
        return (int)ans;
    }

    public static void main(String[] args) {
        String s = new String("+2147483647");
        int num = StrToInt(s);
        System.out.println(num);
    }
}

public class Test {
}
